﻿using System;
using static System.Console;
// ReSharper disable AssignNullToNotNullAttribute

namespace App.Console
{
    public class GaussSeidel
    {
        public void Solve(float[,] matrix, float[] coeficients, int variables, int tolerance)
        {
            var x = new float[variables]; // Valor de X 

            for (var i = 0; i < variables; i++)
            {
                coeficients[i] = coeficients[i] / matrix[i, i];
                for (var j = 0; j < variables; j++)
                {
                    if (i != j) matrix[i, j] = matrix[i, j] / matrix[i, i];
                }
            }

            for (var k = 1; k <= variables; k++)
            {
                for (var i = 0; i < variables; i++)
                {
                    x[i] = coeficients[i];

                    for (var j = 0; j < variables; j++)
                    {
                        if (i != j) x[i] = x[i] - matrix[i, j] * x[j];
                    }
                }
                if (k == variables)
                    for (var i = 0; i < variables; i++)
                    {
                        Write("X{0}={1:F3} \t", i, Math.Round(x[i], 2));
                    }
            }

            ReadKey();
        }
    }
}